package com.coment.po.roles;

import com.coment.cfg.luban.constant.AIDCFG;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.builder.HashCodeExclude;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;

/// 角色
@Slf4j
@Data
@NoArgsConstructor
@ToString(exclude = {"rolePanel"})
@EqualsAndHashCode(of = {"userInfoId", "cardId"})
public class Roles {
    /// id
    @Id
    public String id;

    /// 用户信息id
    @Indexed
    public Integer userInfoId;

    /// 卡牌id
    @Indexed
    public Integer cardId;

    public int skillLv;

    /// 角色面板
    @HashCodeExclude
    public RolePanel rolePanel;


    /// 是否还活着
    @JsonIgnore
    @Transient
    public boolean isSurvive() {
        Double v = this.rolePanel.getAttribute().get(AIDCFG.hp);
        return v > 0;
    }

    /// 怪物构造器
    public Roles(Integer cardId) {
        this(-1, cardId, 1);
    }

    public Roles(Integer userInfoId, Integer cardId) {
        this(userInfoId, cardId, 1);
    }

    public Roles(Integer userInfoId, Integer cardId, Integer level) {
        this.userInfoId = userInfoId;
        this.cardId = cardId;
        this.skillLv = 1;
        this.rolePanel = new RolePanel(userInfoId, cardId, level);
    }
}
